/*--------------------------------------------------------------------------------------------------------------------
 *  -------------------------------------------------------------------------------------------------------------------
 *
 *  Filename: ps_api.h
 *
 *  Description: AT interface prototypes for yuge AT commands
 *
 *  History:
 *  Jan 9, 2020- Li Tang Creation of file
 *
 *  Notes:
 *
 ******************************************************************************/
#ifndef _PS_API_H
#define _PS_API_H

#include "gbl_types.h"



typedef struct _PsSignalInfo_struct
{
	UINT8 csq;
	UINT8 ber;
	INT8 rscp;
	INT8 ecno;
	INT8 rsrq;
	INT8 rsrp;
	INT8 sinr;
}PsSignalInfo;

typedef struct _PsLteScellInfo_struct
{
	UINT16		mcc;
	UINT8		lenOfMnc;   	/**< Length of MNC, value range (2,3) */
	UINT16		mnc;        		/**< 2-3 digits of MNC */
	UINT16		tac;
	UINT16		phyCellId;
	UINT32		dlEuArfcn;
	UINT32		ulEuArfcn;
	UINT16		band;
	UINT8		dlBandwidth;	/*0 - 1.4M, 1 - 3M, 2 - 5M, 3 - 10M, 4 - 15M, 5 - 20M */
	UINT32		cellId;
	
	UINT8		isTdd; 
	UINT8		subframeAssignment;
	UINT8		specialSubframePatterns;

	UINT8		rsrp;
	UINT8		rsrq;
	INT8		sinr;	
	INT16		srxlev; 	
}PsLteScellInfo;	


#define PS_LTE_MAX_NCELL_INTRA 16
#define PS_LTE_MAX_NCELL_INTER 16

typedef struct _PsLteIntraFreqParams_struct
{
	UINT16		phyCellId;
	UINT32		euArfcn;
	UINT8		rsrp;
	UINT8		rsrq;
	UINT16		mcc;
	UINT8		lenOfMnc;   /**< Length of MNC, value range (2,3) */
	UINT16		mnc;        /**< 2-3 digits of MNC */
	UINT16		tac;
	UINT32		cellId;
	INT16		srxlev; 
	UINT8		cellReselectionPriority;
	UINT8		sNonIntraSearch;
	UINT8		threshServingLow;
	UINT16		sIntraSearch;
	INT8		refSignalPower; /**< PDSCH-ConfigCommon.referenceSignalPower. Value range: -60~50, invalid(0x7F). */
}PsLteIntraFreqParams;


typedef struct _PsLteInterFreqParams_struct
{
	UINT16		phyCellId;
	UINT32		euArfcn;
	UINT8		rsrp;
	UINT8		rsrq;
	UINT16		mcc;
	UINT8		lenOfMnc;   /**< Length of MNC, value range (2,3) */
	UINT16		mnc;        /**< 2-3 digits of MNC */
	UINT16		tac;
	UINT32		cellId;
	INT16		srxlev; 
	UINT8		threshXLow;//Value range:0~31 received from SIB5
	UINT8		threshXHigh;//Value range:0~31 received from SIB5
	UINT8		cellReselectionPriority;
	INT8                  refSignalPower; /**< PDSCH-ConfigCommon.referenceSignalPower. Value range: -60~50, invalid(0x7F). */
	UINT8               dlBandwidth;/*0 - 1.4M, 1 - 3M, 2 - 5M, 3 - 10M, 4 - 15M, 5 - 20M */
	UINT16             band;
}PsLteInterFreqParams;


typedef struct _PsLteNcellsInfo_struct
{
	UINT8	numIntraFreq;
	PsLteIntraFreqParams   intraFreq[ PS_LTE_MAX_NCELL_INTRA];	    /**< Inter-Frequency Info. \sa CiDevLteEngInterFreqNcellInfo */

	UINT8	numInterFreq;
	PsLteInterFreqParams   interFreq[ PS_LTE_MAX_NCELL_INTER];	    /**< Inter-Frequency Info. \sa CiDevLteEngInterFreqNcellInfo */	
}PsLteNcellsInfo;

typedef enum PS_CFUN_OP_TYPE
{
	PS_CFUN_OP_MIN_FUNC = 0,  /* Minimum functionality */
	PS_CFUN_OP_FULL_FUNC,     /* Full functionality */
	PS_CFUN_OP_DISABLE_RF_TX,
	PS_CFUN_OP_DISABLE_RF_RX,
	PS_CFUN_OP_DISABLE_RF_RXTX,
	PS_CFUN_OP_UPDATE_NVM_MIN_FUNC,  /* Minimum functionality */
	PS_CFUN_OP_UPDATE_NVM_FULL_FUNC,     /* Full functionality */
	PS_CFUN_OP_UPDATE_NVM_DISABLE_RF_RXTX = 9,

	PS_CFUN_NUM_OP
} _PsCfunOp;

typedef UINT8 PsCfunOp;


typedef enum PsCeregStateEnum
{
	PS_CEREG_STA_NOT_REGED = 0,			/**< Not registered and not searching */
	PS_CEREG_STA_REG_HPLMN, 			/**< Registered on home PLMN */
	PS_CEREG_STA_TRYING,        				/**< Not registered, but cellular subsystem is searching for a PLMN to register to */
	PS_CEREG_STA_REG_DENIED,			/**< Registration denied */
	PS_CEREG_STA_UNKNOWN,				/**< Unknown */
	PS_CEREG_STA_REG_ROAMING, 			/**< Registered on visited PLMN */
	PS_CEREG_STA_SMS_ONLY_HOME,		/**< registered for "SMS only", home network (applicable only when <AcT> indicates E-UTRAN) */
	PS_CEREG_STA_SMS_ONLY_ROAMING,		/**< registered for "SMS only", roaming (applicable only when <AcT> indicates E-UTRAN) */
	PS_CEREG_STA_EMERGENCY_ONLY_NOT_USED,		/**< attached for emergency bearer services only (see NOTE 2) (not applicable) */
	PS_CEREG_STA_CSFB_NOT_PREFERRED_HOME,		/**<registered for "CSFB not preferred", home network (applicable only when <AcT> indicates E-UTRAN) */
	PS_CEREG_STA_CSFB_NOT_PREFERRED_ROAMING,	/**<registered for "CSFB not preferred", roaming (applicable only when <AcT> indicates E-UTRAN) */
	PS_CEREG_STA_REG_EMERGENCY,				/**< attached for emergency bearer services only*/

	PS_CEREG_STA_REG_DENIED_IN_ROAMING,		/**< registeration denied in roaming, only used for SSG project by now*/
	PS_CEREG_STA_SYNC_DONE_IN_LTE_ROAMING,		/**< sync done in LTE roaming network, only used for SSG project by now*/

	PS_CEREG_STA_ECALL_INACTIVE, 				/**< eCall only when camp on LTE for eCall over IMS */

	PS_CEREG_STA_NUM_STATUS                				/**< Number of status values defined */
}_PsCeregState;

typedef UINT8 PsCeregState;

/*****************************************************************
* Function: ps_GetCereg
*
* Description:
* 	该函数用于获取注册状态。
* Parameters:
* 	None
* Return:
* 	 PsCeregState
*****************************************************************/
UINT8 ps_GetCereg(void);

/*****************************************************************
* Function: ps_GetNetworkReady
*
* Description:
* 	该函数用于判定网络数据是否Ready。
* Parameters:
* 	None
* Return:
* 	 0 :  未Ready
* 	 1 :  Ready。
*****************************************************************/
BOOL ps_GetNetworkReady(void);


UINT8 ps_GetRrcState(void);

/*****************************************************************
* Function: ps_GetTac
*
* Description:
* 	该函数用于获取当前小区的Tac。
* Parameters:
* 	None
* Return:
* 	 UINT16： Tac
*****************************************************************/
UINT16 ps_GetTac(void);


/*****************************************************************
* Function: ps_GetCellId
*
* Description:
* 	该函数用于获取当前小区的ID。
* Parameters:
* 	None
* Return:
* 	 UINT32: GetCellId
*****************************************************************/
UINT32 ps_GetCellId(void);

/*****************************************************************
* Function: ps_GetCsq
*
* Description:
* 	该函数用于获取当前信号CSQ（0-99）。
* Parameters:
* 	None
* Return:
* 	 UINT32: CSQ
*****************************************************************/
UINT8 ps_GetCsq(void);

/*
*	================================
*	rsrp 和 rsrq 不同显示换算: 适用于该头文件接口获取的所有rsrp和rsrq
*	0 rsrp < -140 dBm 
*	1 -140 dBm ≤ rsrp < -139 dBm 
*	2 -139 dBm ≤ rsrp < -138 dBm 
*	: : : :
*	95 -46 dBm ≤ rsrp < -45 dBm 
*	96 -45 dBm ≤ rsrp < -44 dBm 
*	97 -44 dBm ≤ rsrp 
*	255 not known or not detectable
*	
*	rsrp = rsrp - 140
*	================================
*	
*	0 rsrq < -19.5 dB 
*	1 -19.5 dB ≤ rsrq < -19 dB 
*	2 -19 dB ≤ rsrq < -18.5 dB 
*	: : : : 
*	32 -4 dB ≤ rsrq < -3.5 dB 
*	33 -3.5 dB ≤ rsrq < -3 dB 
*	34 -3 dB ≤ rsrq 
*	255 not known or not detectable
*	
*	rsrq = 0.5 * rsrq - 19.5
*	================================
*/
/*****************************************************************
* Function: ps_GetRsrp
*
* Description:
* 	该函数用于获取当前信号Rsrp, 计算公式参照上面。
* Parameters:
* 	None
* Return:
* 	 INT8: Rsrp
*****************************************************************/
INT8 ps_GetRsrp(void);

/*****************************************************************
* Function: ps_GetRsrq
*
* Description:
* 	该函数用于获取当前信号Rsrq, 计算公式参照上面。
* Parameters:
* 	None
* Return:
* 	 INT8: Rsrq
*****************************************************************/
INT8 ps_GetRsrq(void);


/*****************************************************************
* Function: dev_GetSIMImsi
*
* Description:
* 	该函数用于获取的主小区信息。
* Parameters:
* 	scellinfo 		[out] 	获取的主小区信息
* 	timeout         [in] 	阻塞获取，超时时间，单位：秒；
* Return:
* 	 TRUE :  成功
* 	 FALSE :  失败
*****************************************************************/
BOOL ps_GetServerCellInfo(PsLteScellInfo *scellinfo, int timeout);


/*****************************************************************
* Function: dev_GetSIMImsi
*
* Description:
* 	该函数用于获取的邻小区信息。
* Parameters:
* 	ncellsinfo 		[out] 	获取的邻小区信息
* 	timeout         [in] 	阻塞获取，超时时间，单位：秒；
* Return:
* 	 TRUE :  成功
* 	 FALSE :  失败
*****************************************************************/
BOOL ps_GetNeighborCellInfo(PsLteNcellsInfo *ncellsinfo, int timeout);


/*****************************************************************
* Function: ps_SetCfun
*
* Description:
* 	该函数用于设置飞行模式。
* Parameters:
* 	cfun 		[int] 	获取的邻小区信息
* 				0：飞行模式
* 				正常模式
* Return:
* 	 TRUE :  成功
* 	 FALSE :  失败
*****************************************************************/
BOOL ps_SetCfun(UINT8 cfun);


/*****************************************************************
* Function: ps_SetCfun
*
* Description:
* 	该函数用于获取飞行模式。
* Parameters:
* 	cfun 		[int] 	获取的邻小区信息
* 				0：飞行模式
* 				1：正常模式
* Return:
* 	0：飞行模式
* 	1：正常模式
*****************************************************************/
UINT8 ps_GetCfun(void);



void ps_SetConfigValue(char *config, int value);

int ps_GetConfigValue(char *config);

#endif

